package javabase.concurrent;

import java.util.Random;

public class ThreadScope {
	
	private static int data = 0;
	  
	private static ThreadLocal<Integer> tl = new ThreadLocal<>();
	static class A {
		public void get() {
			System.out.println("A " + Thread.currentThread().getName() + " "+ data);
			System.out.println("tl A " + Thread.currentThread().getName() + " "+ tl.get());
		}
	}
	
	
	static class B {
		public void get() {
			System.out.println("B " + Thread.currentThread().getName() + " " + data);
			System.out.println("tl B " + Thread.currentThread().getName() + " "+ tl.get());
		}
	}
	
	public static void main(String[] args) {
		for(int i=0; i<2; i++) {
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					tl.set(new Random().nextInt());
					new A().get();
					new B().get();
				}
			}).start();
		}
	}
	
}
